<template>
  <div class="age">
    <div class="age_top">
      <p class="age_title">年龄比例</p>
      <p class="age_bg"></p>
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang='ts'>
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue';

let charts = ref()
onMounted(() => {
  let mycharts = echarts.init(charts.value)
  let option = {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      right: 'right',//图例组件在最右侧
      orient: 'vertical',//调整图例组件方向垂直
      textStyle: {
        color: 'white',
        fontSize: '14px'
      },
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2,
        },
        label: {
          show: true,
          position: 'inside',
          color: 'white',
          fontSize: '12px'

        },
        labelLine: {
          show: false
        },
        data: [
          { value: 1600, name: '10岁以下' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union' },
          { value: 300, name: 'Ads' }
        ],
        width: "100%",
        height: "100%",
      }
    ],
    // 调整图形图标的位置
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
    },
  };
  mycharts.setOption(option)
})
</script>

<style scoped>
.age {
  margin-top: 20px;
  background: url(../../../images/dataScreen-main-lb.png) no-repeat;
  background-size: 100% 100%;

  .age_top {
    margin-left: 20px;

    .age_title {
      color: white;
      font-size: 20px;
    }

    .age_bg {
      margin-top: 10px;
      width: 68px;
      height: 7px;
      background: url(../../../images/dataScreen-title.png) no-repeat;
      background-size: 100% 100%;

    }
  }

  .charts {
    height: 260px;
  }
}
</style>